<?php
session_start();
include ("inc/validate_user.inc");
require_once('inc/db_access.inc');
require_once('inc/notes.inc');

$uid =  $_SESSION['uid'];

$tags = $_REQUEST['tags'];
$dbc = new DBConnection();
$dbc->getNewConnection();

if(!$tags){
	?>
	<form method='post' action="<?php echo $_SERVER['PHP_SELF']; ?>" >
	Tags : <input autocomplete='false' name='tags' ><br/>
	<input type='submit' >
	<?php
} else {
	$tgs = array();
	$tag = strtok($tags,",");
	while($tag){
		$t = trim($tag);
		$tgs[] = $t;
		$tag = strtok(",");
	}
	$notes = get_tag_notes($dbc, $uid, $tgs);
	?>
	<ul>
	<?php 
	foreach ($notes as $note){
	$nid = $note[0];
	$n = $note[1];
	echo "<li><p id='$nid' >$n</p></li>\n";
	}
	?>
	</ul>
	<?php
}
?>
